<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>雷电模拟器</title>
<link rel="stylesheet" href="./css/element/index.css">
<link rel="icon" href="https://res.ldmnq.com/gw/assets/images/05/favicon.ico" type="image/svg+xml">
</head>
<body>

<div id="app">
	<template>
		<el-card class="fixed-top">
	    <el-row v-for="(value, key) in mnqcall" :key="key" style="margin-top: 5px;margin-bottom: 5px;">
	    		<el-tag>{{value.name}}</el-tag>&nbsp;
	    		<el-tag type="warning">{{value.data}}</el-tag>
	    </el-row>
	  </el-card>
  </template>
	<template>
		<div>
			<el-card v-for="(items, path) in mnqlist" :key="path" style="margin-top: 5px;">
				<el-row type="flex" style="margin-bottom: 10px;">
					<el-tag type="success">{{path}}</el-tag>
					<div style="flex-grow: 1;"></div>
					<el-tag type="warning" style="color:#868686; width:150px;">{{get_diskusage(path)}}</el-tag>&nbsp;
					<el-tag type="warning" style="color:#00c1c1;">{{get_mnqmodel(path)}}</el-tag>&nbsp;
					<el-button type="success" size="mini" style="width:85px;" @click="newDialog.show=true; newDialog.path=path" plain>新建</el-button>
				</el-row>
        <el-row v-for="(item, key) in items" :key="key" type="flex" justify="space-between" style="margin-top: 5px;">
          <el-tag @click="item.edit=true">{{item.id}}</el-tag>&nbsp;
          <el-tag type="info" v-show="!item.edit">{{item.name}}</el-tag>
          <el-input 
          	v-show="item.edit" 
          	v-model="item.name" 
          	size="small" 
          	placeholder="重命名名称" 
          	@change="mnq_set_name(item, path)" 
          	@keyup.enter.native="mnq_set_name(item, path)"></el-input>
          <div style="flex-grow: 1;"></div>
          <el-tag type="info" style="width:80px;">{{item.size}}</el-tag>&nbsp;&nbsp;
          <el-button type="info" size="mini" @click="button_call(path, item)" plain>任务</el-button>
          <el-button
          	v-show="item.isrunning"
          	size="mini"
          	type="danger"
          	@click="button_StartStop(path, item, 'stop')"
          	:disabled="item.gb"
          	plain>关闭</el-button>
          <el-button
          	v-show="!item.isrunning"
          	size="mini"
          	type="primary"
          	@click="button_StartStop(path, item, 'start')"
          	:disabled="item.qd"
          	plain>启动</el-button>
          <el-button
          	size="mini"
          	@click="hyDialog.show=true; hyDialog.item=item; hyDialog.path=path;"
          	:disabled="item.hy">还原</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="button_delete(path, item, 'del')"
            :disabled="item.sc">删除</el-button>
        </el-row>
      </el-card>
		</div>
		<div style="margin-top: 10px;">
			<el-card>
				<el-row type="flex" style="margin-bottom: 15px;">
					<el-upload
					  class="avatar-uploader"
					  action="/upldbk"
					  name="file"
					  :show-file-list="false"
					  :on-progress="uploadProgress"
					  :on-success="handleAvatarSuccess"
					  :before-upload="beforeAvatarUpload">
					  <el-button class="avatar" size="small">上传备份</el-button>
					</el-upload>
					<div style="flex-grow: 1;"></div>
					<el-button size="small" type="warning" plain @click="button_mnq_status()">任务状态</el-button>
				</el-row>
				<el-table
			    :data="mnqldbk"
			    border
			    style="width: 100%;"
			    size="mini"
			    :header-cell-style="{ display: 'none' }">
			    <el-table-column
			      align="right"
			      width="80">
			      <template 
		      		slot-scope="scope">
		        	<el-button @click="button_getldbk(scope.row)" size="mini" type="success" plain>下载</el-button>
		      	</template>
			    </el-table-column>
			    <el-table-column
			      prop="ldbk"
			      label="文件名称"
			      width="300">
			    </el-table-column>
			    <el-table-column
			    	align="center"
			      prop="size"
			      label="文件大小"
			      width="100">
			    </el-table-column>
			    <el-table-column
			    	align="center"
			      prop="name"
			      label="任务对象">
			    </el-table-column>
			    <el-table-column
			      align="right"
			      width="80">
			      <template 
		      		slot-scope="scope">
		        	<el-button @click="button_delldbk(scope.row)" size="mini" type="danger" plain>删除</el-button>
		      	</template>
			    </el-table-column>
			  </el-table>
			</el-card>
		</div>
	</template>
	<template>
	  <el-dialog :visible.sync="hyDialog.show" :close-on-click-modal="false" title="备份还原">
	  	<el-button size="mini" type="primary" @click="button_backup()" plain>备份当前设备</el-button>
	  	<el-row style="text-align: center;">
	  		<span >[ {{ hyDialog.label }} ] 备份</span>
	  	</el-row>
	  	<el-row style="text-align: center;margin-top: 10px;">
	  		<el-tag type="info" style="color:#ff5500">还原对象: [{{get_mnqmodel(hyDialog.path)}}] [ {{hyDialog.item.id}} ] [ {{ hyDialog.item.name }} ]</el-tag>
	  	</el-row>
	    <el-row type="flex" style="margin-top: 5px;">
	    	<el-select v-model="hyDialog.value" @change="handleSelectChange" style="flex-grow: 1;" placeholder="请选择">
			    <el-option
			      v-for="item in mnqldbk"
			      :key="item.ldbk"
			      :label="item.ldbk"
			      :value="item.ldbk">
			    </el-option>
			  </el-select>
			  <el-button @click="button_restore()" plain>还原</el-button>
	    </el-row>
	  </el-dialog>
  </template>
  <template>
	  <el-dialog :visible.sync="newDialog.show" :close-on-click-modal="false" title="[新建/复制] 模拟器">
	  	<el-row type="flex">
	  		<el-tag>数量:</el-tag>&nbsp;
	  		<el-input type="number" v-model="newDialog.number" size="small" placeholder="请输入数量"></el-input>
	  	</el-row>
	  	<el-row type="flex" style="margin-top: 15px;">
	  		<el-tag>名称:</el-tag>&nbsp;
	  		<el-input v-model="newDialog.name" size="small" placeholder="请输入名称"></el-input>
	  	</el-row>
	  	<el-row type="flex" style="margin-top: 15px;" v-show="newDialog.fromshow">
	  		<el-tag>复制:</el-tag>&nbsp;
	  		<el-select v-model="newDialog.index" size="small" style="flex-grow: 1;" placeholder="请选择">
			    <el-option
			      v-for="item in mnqlist[newDialog.path]"
			      :key="item.id"
			      :label="`${item.id} - ${item.name}`"
			      :value="item.id">
			    </el-option>
			  </el-select>
	  	</el-row>
	  	<el-row style="margin-top: 15px;">
  			<el-radio-group 
          style="width: 100%;text-align: center;" 
          v-model="newDialog.model" 
          border="true"
          @input="handRadioGroup"
          size="small">
          <el-radio-button label="add">新建</el-radio-button>
          <el-radio-button label="copy">复制</el-radio-button>
        </el-radio-group>
	  	</el-row>
	  	<el-row style="margin-top: 15px;">
	  		<el-button @click="button_CopyNew()" size="mini" style="width: 100%;" type="primary" plain>确定</el-button>
	  	</el-row>
	  </el-dialog>
  </template>
  <template>
  	<el-dialog :visible.sync="mnqusDialog.show" :close-on-click-modal="false" title="模拟器任务状态" width="70%">
  		<el-row v-for="(item, key) in mnqusDialog.value" :key="key" type="flex">
  			<el-tag>{{item.status_model}}</el-tag>&nbsp;
  			<el-tag>{{item.mnq_value}}</el-tag>&nbsp;
  			<el-tag>{{item.cal_name}}</el-tag>&nbsp;
  			<div style="flex-grow: 1;"></div>
  			<el-tag :type="get_mnq_status(item.code)">{{item.status_code}}</el-tag>
  			<el-tag>{{item.status_time2}} [{{item.status_time1}}]</el-tag>
  		</el-row>
  	</el-dialog>
  </template>
  <template>
	  <el-dialog :visible.sync="callDialog.show" title="关联任务">
	  	<el-row v-for="(item, key) in callDialog.value" :key="key" type="flex">
	  		<el-tag>{{item.task_name}}</el-tag>
	  		<el-tag>{{item.task_id}}</el-tag>
	  		<div style="flex-grow: 1;"></div>
	  		<el-button v-if="findisinmodelcall(item.devices_list)" @click="button_call_model(item, 'add')" size="mini" type="primary" plain>加入任务</el-button>
	  		<el-button v-else @click="button_call_model(item, 'del')" size="mini" type="danger" plain>移出任务</el-button>
	  	</el-row>
	  </el-dialog>
  </template>
	<el-progress v-show="progress.show" type="circle" :percentage="progress.percentCompleted" color="#e6a23c" class="progress-bar"></el-progress>
</div>

</body>
<style>
.fixed-top {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: #909399;
  border-radius: 3px;
}
.progress-bar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
}
</style>
<script src="./js/vue/vue.js"></script>
<script src="./js/element/index.js"></script>
<script src="./js/axios/qs.min.js"></script>
<script src="./js/axios/axios.min.js"></script>
<script>
	function formatRelativeTime(timestamp) {
		timestamp = timestamp * 1000;
    const now = new Date().getTime();
    const diff = now - timestamp;

    const second = 1000;
    const minute = second * 60;
    const hour = minute * 60;
    const day = hour * 24;
    const month = day * 30; // 大致平均每月天数

    if (diff < minute) {
        return '刚刚';
    } else if (diff < hour) {
        return Math.floor(diff / minute) + '分钟前';
    } else if (diff < day) {
        return Math.floor(diff / hour) + '小时前';
    } else if (diff < month) {
        return Math.floor(diff / day) + '天前';
    } else {
        const monthsAgo = Math.floor(diff / month);
        return monthsAgo === 1 ? '1个月前' : `${monthsAgo}个月前`;
    }
	}

	function formatTimestamp(timestamp) {
		timestamp = timestamp * 1000;
    const date = new Date(timestamp);

    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份是从 0 开始的，所以加 1
    const day = ('0' + date.getDate()).slice(-2);
    const hours = ('0' + date.getHours()).slice(-2);
    const minutes = ('0' + date.getMinutes()).slice(-2);
    const seconds = ('0' + date.getSeconds()).slice(-2);

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
	}

	function getKeyByValue(object, value) {
  		return Object.keys(object).find(key => object[key] === value);
	}

	function Myround(num) {
	  return Math.round(num * 100) / 100;
	}

	function initWebSocket(vueobj, wsport) {
		var websock = new WebSocket("ws://" + window.location.hostname + ":" + wsport);
	  websock.onclose = function(event) {
	  	console.log("断开连接，30秒重连")
	  	setTimeout(function () {
				initWebSocket(vueobj, wsport);
			}, 30000);
	  };
	  websock.onopen = function(event) {console.log('连接成功')};
	  websock.onmessage = function(event) {websocketonmessage(event, vueobj)};
	}

	function websocketonmessage(event, vueobj) {
		let eve_data = JSON.parse(event.data)
		if (eve_data.type === "clent_add") {
			let item = eve_data.value
			if (item.name === "复制模拟器") {
				let tabel = vueobj.mnqlist[item.args[0]][item.args[3]]
				Object.assign(tabel, { sc: true, hy: true, qd: true, gb: true });
			} else if (item.name === "还原模拟器") {
				let tabel = vueobj.mnqlist[item.args[0]][item.args[1]]
				Object.assign(tabel, { sc: true, hy: true, qd: true, gb: true });
			} else if (item.name === "备份模拟器") {
				let tabel = vueobj.mnqlist[item.args[0]][item.args[1]]
				Object.assign(tabel, { sc: true, hy: true, qd: true, gb: true });
			}
			vueobj.$set(vueobj.mnqcall, eve_data.uid, item);

		} else if (eve_data.type === "clent_del") {
			if (vueobj.mnqcall.hasOwnProperty(eve_data.uid)) {
				let item = vueobj.mnqcall[eve_data.uid];
				if (item.name === "复制模拟器") {
					let tabel = vueobj.mnqlist[item.args[0]][item.args[3]]
					Object.assign(tabel, { sc: false, hy: false, qd: false, gb: false });
					vueobj.one_diskusage(item.args[0])
				} else if (item.name === "还原模拟器") {
					let tabel = vueobj.mnqlist[item.args[0]][item.args[1]]
					Object.assign(tabel, { sc: false, hy: false, qd: false, gb: false });
					vueobj.one_diskusage(item.args[0])
				} else if (item.name === "新建模拟器") {
					vueobj.one_diskusage(item.args[0])
				} else if (item.name === "备份模拟器") {
					let tabel = vueobj.mnqlist[item.args[0]][item.args[1]]
					Object.assign(tabel, { sc: false, hy: false, qd: false, gb: false });
				}
			}
			vueobj.$delete(vueobj.mnqcall, eve_data.uid);

		} else if (eve_data.type === "mnq_add") {
			let item = eve_data.value
			Object.assign(item, { sc: item["isrunning"], hy: item["isrunning"], qd: item["isrunning"], gb: !item["isrunning"] });
			vueobj.$set(vueobj.mnqlist[eve_data.path], item["id"], item);
			vueobj.one_diskusage(eve_data.path)

		} else if (eve_data.type === "mnq_del") {
			if (eve_data.status === false) {
				for (let item of eve_data.value) {
					vueobj.$delete(vueobj.mnqlist[eve_data.path], item);
					vueobj.one_diskusage(eve_data.path)
				}
			}

		} else if (eve_data.type === "mnq_start") {
			let item = vueobj.mnqlist[eve_data.path][eve_data.value]
			Object.assign(item, { sc: !eve_data.status, hy: !eve_data.status, qd: eve_data.status, gb: eve_data.status, isrunning: !eve_data.status });

		} else if (eve_data.type === "mnq_stop") {
			let item = vueobj.mnqlist[eve_data.path][eve_data.value]
			Object.assign(item, { sc: eve_data.status, hy: eve_data.status, qd: eve_data.status, gb: eve_data.status, isrunning: eve_data.status });
    
		} else if (eve_data.type === "mnq_set") {
			let item = eve_data.value
			vueobj.$set(vueobj.mnqlist[eve_data.path][item["id"]], item["key"], item["value"]);

		}else if(eve_data.type === "mnq_restore"){
			let item = vueobj.mnqlist[eve_data.path][eve_data.value.id]
			Object.assign(item, { size: eve_data.value.size });

		} else if(eve_data.type === "mnq_backup"){
			if (vueobj.mnqldbk.some(obj => obj.ldbk === eve_data.value.ldbk) === false) {
				vueobj.mnqldbk.push(eve_data.value);
			}
			
		}else if (eve_data.type === "ldbk_add") {
			if (vueobj.mnqldbk.some(obj => obj.ldbk === eve_data.value.ldbk) === false) {
				vueobj.mnqldbk.push(eve_data.value);
			}

		} else if (eve_data.type === "ldbk_del") {
			if (vueobj.mnqldbk.some(obj => obj.ldbk === eve_data.value)) {
				let devices = vueobj.mnqldbk.filter(obj => obj.ldbk !== eve_data.value);
				vueobj.$set(vueobj, "mnqldbk", devices)
			}
			
		} else if (eve_data.type === "call_add") {
			for (let item of eve_data.value) {
				Object.assign(item, { sc: item["isrunning"], hy: item["isrunning"], qd: item["isrunning"], gb: !item["isrunning"] });
				vueobj.$set(vueobj.mnqlist[eve_data.path], item["id"], item);
			}
			vueobj.one_diskusage(eve_data.path)
			
		} else if (eve_data.type === "call_del") {
			for (let item of eve_data.value) {
				vueobj.$delete(vueobj.mnqlist[eve_data.path], item);
			}
			vueobj.one_diskusage(eve_data.path)

		} else if (eve_data.type === "save_file") {
			if (eve_data.model === "add") {
				eve_data.value["status_time1"] = formatRelativeTime(eve_data.value["ping_time"]);
		      	eve_data.value["status_time2"] = formatTimestamp(eve_data.value["ping_time"]);
		      	if (eve_data.value["code"] === 0) {
		      		eve_data.value["status_code"] = "未连接"
		      	} else if (eve_data.value["code"] === 1) {
		      		eve_data.value["status_code"] = "连接中"
		      	} else if (eve_data.value["code"] === 2) {
		      		eve_data.value["status_code"] = "已完成"
		      	} else {
		      		eve_data.value["status_code"] = "未知"
		      	}
      			eve_data.value["status_model"] = vueobj.get_mnqmodel(eve_data.value["cal_path"])
				vueobj.$set(vueobj.mnqusDialog.value, eve_data.value["id"], eve_data.value);

			} else if (eve_data.model === "del") {
				vueobj.$delete(vueobj.mnqusDialog.value, eve_data.value);

			} else if (eve_data.model === "set") {
				let item = vueobj.mnqusDialog.value[eve_data.value["id"]]
				if (eve_data.value["key"] === "ping_time") {
					item["ping_time"] = eve_data.value["value"]
					item["status_time1"] = formatRelativeTime(item["ping_time"]);
      				item["status_time2"] = formatTimestamp(item["ping_time"]);
				} else if (eve_data.value["key"] === "code") {
					item["code"] = eve_data.value["value"]
					if (item["code"] === 0) {
	      				item["status_code"] = "未连接"
	      			} else if (item["code"] === 1) {
	      				item["status_code"] = "连接中"
	      			} else if (item["code"] === 2) {
	      				item["status_code"] = "已完成"
	      			} else {
	      				item["status_code"] = "未知"
	      			}
				}
				vueobj.$set(vueobj.mnqusDialog.value, eve_data.value["id"], item);
			}

		} else if (eve_data.type === "leidian_error") {
			//刷新页面可重置所有状态

		} else if (eve_data.type === "init") {
			for (let item in eve_data.data) {
				vueobj.$set(vueobj.mnqcall, item, eve_data.data[item]);
			}
		}
	}
	
	new Vue({
      el: '#app',
      data: {
      	mnqlist: {},
      	mnqmodel: {},
      	mnqldbk: [],
      	mnqcall: {},
      	diskusage: {},
      	supx: "",
      	android_version: {},
      	progress: {show: false, percentCompleted: 0},
      	hyDialog: {show: false, value: "", label: "", item: {}, path:null},
      	newDialog: {show: false, path:null, model:"add", name:"", number:1, fromshow: false, index: ""},
      	callDialog: {show: false, path:null, value:{}, item:null},
      	mnqusDialog: {show: false, value: {}},
      },
      created() {
      	this.api_get("/windows", { model: "getmnqmodel" }, this.api_init_data)     	
		this.api_get("/windows", { model: "ldbk", type: "see" }, this.ldbk_model_init);
		setInterval(() => {
        	for (let mid in this.mnqusDialog.value) {
      			this.$set(this.mnqusDialog.value[mid], "status_time1", formatRelativeTime(this.mnqusDialog.value[mid]["ping_time"]));
      		}
      	}, 60000);
      },
      methods: {
      	handleSelectChange(value) {
      		const selected = this.mnqldbk.find(option => option.ldbk === value);
      		this.hyDialog.label = selected.name;
      	},
      	handleAvatarSuccess(res, file) {
      		this.progress.show = false;
        	this.pop_message('success', '[ ' + file.name + ' ] 上传完成')
      	},
      	beforeAvatarUpload(file) {
	        let ldbkend = file.name.endsWith(this.supx)
	        if (!ldbkend) {
	        	this.pop_message('error','上传文件只支持 ' + this.supx + ' 格式')
	        }else{
	        	this.progress.show = true;
	        	this.progress.percentCompleted = 0;
	        }
	        return ldbkend;
	      },
	      uploadProgress(event, file, fileList) {
	      	this.progress.percentCompleted = Math.floor(event.percent);
	      },
	      handRadioGroup(value) {
	      	this.newDialog.fromshow = value === "copy"
	      },
	    api_init_data(obj, ret) {
	    	if (ret["code"] === 1) {
	    		obj.supx = ret["sux"];
	    		obj.android_version = ret["version"]
	    		const links = document.querySelectorAll('link[rel~="icon"]');
			    	links.forEach(link => {
			        	link.href = ret["url"];
			    });
	    		document.title = ret["name"];
	    		initWebSocket(obj, ret["wsport"])
	    	}
	    	obj.api_get("/windows", { model: "list" }, obj.list_model_init);
	    },
      	list_model_init(obj, ret) {
      		if (ret["code"] === 1) {
      			const table = ret["msg"]
      			for (let items in table) {
      				let item = table[items]
      				for (let _item in item) {
      					let one = item[_item]
      					one["sc"] = one["isrunning"]
      					one["hy"] = one["isrunning"]
      					one["qd"] = one["isrunning"]
      					one["gb"] = !one["isrunning"]
      					one["edit"] = false
      				}
      			}
      			obj.mnqlist = table
      			obj.mnqmodel = ret["model"]
      			obj.init_diskusage()
      		}
      	},
      	ldbk_model_init(obj, ret) {
      		if (ret["code"] === 1) {
      			obj.mnqldbk = ret["msg"]
      		}
      	},
      	get_mnq_status(code) {
      		if (code === 0) {
      			return "danger"
      		} else if (code === 1) {
      			return "success"
      		} else if (code === 2) {
      			return "warning"
      		} else {
      			return "info"
      		}
      	},
      	mnq_set_name(value, path) {
      		value.edit = false
      		this.api_get("/custom", {model:"mnq_custom", value: "rename " + value.id + " " + value.name, path:path}, (obj, ret) => {})
      	},
      	init_diskusage() {
      		for (let key in this.mnqmodel) {
				if (this.mnqmodel.hasOwnProperty(key)) {
					let path = this.mnqmodel[key]
					this.api_get("/windows", {model:"diskusage", path:path}, (obj, ret) => {
						if (ret["code"] === 1) {
							obj.$set(obj.diskusage, path, "余 " + Myround(ret["msg"][2]) + "GB [" + Myround(ret["msg"][3]) + "%]");
						}
					})
				}
			}
      	},
      	one_diskusage(path) {
      		for (let key in this.mnqmodel) {
      			if (this.mnqmodel[key] !== null) {
      				if (this.mnqmodel[key].charAt(0) === path.charAt(0)) {
      					this.api_get("/windows", {model:"diskusage", path:this.mnqmodel[key]}, (obj, ret) => {
      						if (ret["code"] === 1) {
      							obj.$set(obj.diskusage, obj.mnqmodel[key], "余 " + Myround(ret["msg"][2]) + "GB [" + Myround(ret["msg"][3]) + "%]");
      						}
      					})
      				}
      			}
      		}
      	},
      	findisinmodelcall(item) {
      		return !item.some(obj => obj.index === this.callDialog.item.id);
      	},
      	button_call_model(item, model) {
      		this.api_get("/set", {model: model, id: item.task_id, index: this.callDialog.item.id}, (obj, ret) => {
      			if (ret["code"] === 1) {
	      			devices = obj.callDialog.value[item.task_id]["devices_list"]
	      			if (model === "add") {
	      				devices.push({index:obj.callDialog.item.id})
	      			} else if (model === "del") {
	      				devices = devices.filter(ob => ob.index !== obj.callDialog.item.id);
	      			}
	      			obj.$set(obj.callDialog.value[item.task_id], "devices_list", devices)
	      		}
      		})
      	},
      	button_mnq_status() {
      		this.mnqusDialog.show = true;
      		this.api_get("/see", {model: "dict"}, (obj, ret) => {
      			if (ret["code"] === 1) {
      				let calltabel = {}
      				for (let item in ret["msg"]) {
      					let _item = ret["msg"][item]
      					_item["status_time1"] = formatRelativeTime(_item["ping_time"]);
      					_item["status_time2"] = formatTimestamp(_item["ping_time"]);
      					if (_item["code"] === 0) {
      						_item["status_code"] = "未连接"
      					} else if (_item["code"] === 1) {
      						_item["status_code"] = "连接中"
      					} else if (_item["code"] === 2) {
      						_item["status_code"] = "已完成"
      					} else {
      						_item["status_code"] = "未知"
      					}
      					_item["status_model"] = obj.get_mnqmodel(_item["cal_path"])
      					calltabel[_item["id"]] = _item
      				}
      				obj.mnqusDialog.value = calltabel
      			}
      		})
      	},
      	button_delldbk(item) {
      		this.$confirm('确定删除 [' + item.name + '] 备份吗?', '提示', {
	          	confirmButtonText: '确定',
	          	cancelButtonText: '取消',
	          	type: 'danger'
	        }).then(() => {
	          	let call = function(obj, ret) {
	            	if (ret["code"] === 1 ) {
	              		obj.pop_message('success','删除成功!')
	            	}else{
	              		obj.pop_message('error','删除失败!' + ret["msg"])
	            	}
	          	}
	          	this.api_get("/windows", { model: "ldbk", type: "del", file: item.ldbk}, call)
	        }).catch(() => {
	          	this.pop_message('info','已取消删除')         
	        })
      	},
      	button_getldbk(item) {
      		let link = document.createElement('a');
	        link.href = "/getldbk?name=" + item.ldbk;
	        link.download = item.ldbk;
	        document.body.appendChild(link);
	        link.click();
	        document.body.removeChild(link);
      	},
      	button_CopyNew() {
      		this.newDialog.show = false
      		let dict = {
      			model: this.newDialog.model, 
      			sum: this.newDialog.number,  
      			path: this.newDialog.path,
      			index: this.newDialog.index,
      		}
      		if (this.newDialog.name !== "") {
      			dict["name"] = this.newDialog.name
      		}
      		this.api_get("/leidian", dict, (obj, ret) => {})
      	},
      	button_backup() {
      		this.hyDialog.show = false
      		this.api_get("/leidian", {
      			model: "backup",  
      			index: this.hyDialog.item.id, 
      			path: this.hyDialog.path
      		}, (obj, ret) => {})
      	},
      	button_restore() {
      		this.hyDialog.show = false
      		this.api_get("/leidian", {
      			model: "restore", 
      			file: this.hyDialog.value, 
      			index: this.hyDialog.item.id, 
      			path: this.hyDialog.path
      		}, (obj, ret) => {})
      	},
      	button_call(path, mid) {
      		this.callDialog.show = true;
      		this.callDialog.item = mid;
      		this.api_get("/see", {model:"list", path:path}, (obj, ret) => {
      			if (ret["code"] === 1) {
      				obj.callDialog.value = ret["msg"]
      			}
      		})
      	},
      	button_delete(path, mid, model) {
      		this.$confirm('确定删除 [' + mid.id + '-' + mid.name + '] ', '提示', {
	          	confirmButtonText: '确定',
	          	cancelButtonText: '取消',
	          	type: 'danger'
	        }).then(() => {
	          	this.api_get("/leidian", {model: model, index: mid.id, path: path}, (obj, ret) => {})
	        }).catch(() => {
	          	this.pop_message('info','已取消删除')         
	        })
      	},
      	button_StartStop(path, mid, model) {
	        this.api_get("/leidian", {model: model, index: mid.id, path: path}, (obj, ret) => {})
      	},
      	get_mnqmodel(value) {
      		key = getKeyByValue(this.mnqmodel, value)
      		if (this.android_version.hasOwnProperty(key)) {
      			return this.android_version[key]
      		}
      		return ""
      	},
      	get_diskusage(value) {
      		return this.diskusage[value]
      	},
      	api_get(url, dict, call) {
	        axios.get(url, { params: dict }).then(
	          	ret=>{
	            	call(this, ret.data)
	          	}
	        ).catch(error=>{
	          	console.log(error)
	          	this.pop_message('error', error)
	        })
	    },
        pop_message(type, mesg) {
          	this.$message({
            	type: type,
            	message: mesg
          	})
        },
      }
});
</script>
</html>